package com.baturu.vin.gm.script.DAO;

import com.baturu.vin.gm.script.DTO.PartsDTO;
import com.baturu.vin.gm.script.DTO.PartsmappingDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: chenjiahao
 * @Time: 2019/3/22
 */
public interface PartsDAO {

    @Select("select max(id) from tmp_0404")
//    @Select("select max(id) from tmp_vin_partname_0414 ")
    Integer queryMaxId();

    @Select({"<script>SELECT '雪佛兰' brand ,t.orderKey,t.partsCode,positionNum,t.partsName ,t.imageCode  FROM `tmp_parts_20190322` t",
//            "LEFT JOIN gm_parts_mapping t1 on t.partsCode = t1.partsCode ",
            "where  t.id &gt; ${start} and t.id &lt;= ${end}</script> ",})
    List<PartsDTO> queryParts(@Param("start") Integer start, @Param("end") Integer end);

    @Insert({"<script>",
            "INSERT Ignore INTO vinanalysis.inventory_sort (brand,orderKey,partsCode,positionNum,partsName,imageCode) values",
            "<foreach item = 'dto' index='index' collection = 'list' open = '(' separator='),(' close = ')'>",
            "#{dto.brand},#{dto.orderKey},#{dto.partsCode},#{dto.positionNum},#{dto.partsName},#{dto.imageCode}",
            "</foreach>",
            "</script>"
    })
    int insert(@Param("list") List<PartsDTO> data);


    @Select({"select * from tmp_0404 where id <= ${end} and id > ${start}"})
    List<PartsmappingDTO> get(@Param("start") int start, @Param("end") int end);

    @Insert({"<script>",
//            "INSERT Ignore INTO tmp_0404_1 (epcId,btrid,vin,partsCode,partsname,cata, groupCode, groupDesc, subject, callout, partNameCn, body) values",
            "INSERT Ignore INTO tmp_parts_btrid_detail_vin_0413 (epcId,btrid,parts_code,partsname,cata, group_Code, group_Desc, subject, callout, Part_Name_CN, body) values",
            "<foreach item = 'dto' index='index' collection = 'list' open = '(' separator='),(' close = ')'>",
            "#{dto.epcId},#{dto.btrid},#{dto.partsCode},#{dto.partsname},#{dto.cata}, #{dto.groupCode}, #{dto.groupDesc}, #{dto.subject}, #{dto.callout}, #{dto.partNameCn}, #{dto.body}",
            "</foreach>",
            "</script>"
    })
    int insertdata(@Param("list") List<PartsmappingDTO> data);

}
